package com.goldmantis.alitrip.controller;

import com.goldmantis.alitrip.service.FlightCityService;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlitripBtripFlightCitySuggestRequest;
import com.taobao.api.response.AlitripBtripFlightCitySuggestResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @Author:Shmily
 * @Description:
 * @Date:Create in 14:24 2018/1/15
 */
@Controller
@CrossOrigin(value = "*",maxAge = 3600)
@RequestMapping("flight/city/")
public class FlightCityController {
    @Autowired
    private FlightCityService flightCityService;

    /**
     * 机票城市建议
     * @param cityName
     * @param userId
     * @return
     */
    @RequestMapping(value = "suggest",method = RequestMethod.GET)
    public ResponseEntity<AlitripBtripFlightCitySuggestResponse> suggest(@RequestParam("cityName") String cityName, @RequestParam("userId") String userId) {
        try {
            cityName=new String(cityName.getBytes("ISO-8859-1"),"UTF-8");
            AlitripBtripFlightCitySuggestResponse rsp = flightCityService.getFlightCitySuggest(cityName,userId);
            return ResponseEntity.ok(rsp);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

}
